
# 849. 到最近的人的最大距离v

def maxDistToClosest(seats):
    dp = [0] * len(seats)
    if seats[0] == 1:
        dp[0] = 0
    else:
        dp[0] = 1
    for i in range(1, len(seats)):
        if seats[i] == 1:
            dp[i] = 0
        else:
            dp[i] = dp[i - 1] + 1
    for j in range(len(seats)-2,-1,-1):
        if 1 not in seats[0:j + 1]:
            break
        if seats[j]==1:
            dp[j] = 0
        else:
            if dp[j+1]==0:
                dp[j] = 1
            else:
                dp[j] = min(dp[j+1]+1,dp[j])
    return max(dp)


if __name__ == "__main__":
    seats = [0,1,0,0,0,0,0,0,1,1,0,1,1]
    print(maxDistToClosest(seats))